home *** CD-ROM | disk | FTP | other *** search
/ Explorer - Mosaic & Web / Explorer - Mosaic & Web.iso / helpers / ghostvew / src / gvcmisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-01  |  12.1 KB  |  326 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvcmisc.c */
  19. /* Miscellaneous GSview routines common to Windows and PM */
  20.  
  21. #ifdef _Windows
  22. #include "gvwin.h"
  23. #else
  24. #include "gvpm.h"
  25. #endif
  26.  
  27. /* display error message and post quit message */
  28. void 
  29. error_message(char *str)
  30. {
  31.     message_box(str, MB_ICONHAND);
  32.     PostQuitMessage(0);
  33. }
  34.  
  35. void
  36. info_init(HWND hwnd)
  37. {
  38.     char buf[MAXSTR];
  39.     int n;
  40.     if (psfile.name[0] != '\0') {
  41.     SetDlgItemText(hwnd, INFO_FILE, psfile.name);
  42.     if (doc) {
  43.         if (doc->ctrld)
  44.         load_string(IDS_NOTDSC, buf, sizeof(buf));
  45.         else  {
  46.         if (doc->epsf) {
  47.             switch (psfile.preview) {
  48.             case IDS_EPSI:
  49.               load_string(IDS_EPSI, buf, sizeof(buf));
  50.               break;
  51.             case IDS_EPST:
  52.               load_string(IDS_EPST, buf, sizeof(buf));
  53.               break;
  54.             case IDS_EPSW:
  55.               load_string(IDS_EPSW, buf, sizeof(buf));
  56.               break;
  57.             default:
  58.               load_string(IDS_EPSF, buf, sizeof(buf));
  59.             }
  60.         }
  61.         else
  62.             load_string(IDS_DSC, buf, sizeof(buf));
  63.         }
  64.         SetDlgItemText(hwnd, INFO_TYPE, buf);
  65.         SetDlgItemText(hwnd, INFO_TITLE, doc->title ? doc->title : "");
  66.         SetDlgItemText(hwnd, INFO_DATE, doc->date ? doc->date : "");
  67.         sprintf(buf, "%d %d %d %d", doc->bbox.llx, doc->bbox.lly, 
  68.         doc->bbox.urx, doc->bbox.ury);
  69.         SetDlgItemText(hwnd, INFO_BBOX, buf);
  70.         switch(doc->orientation) {
  71.         case LANDSCAPE:
  72.             load_string(IDS_LANDSCAPE, buf, sizeof(buf));
  73.             break;
  74.         case PORTRAIT:
  75.             load_string(IDS_PORTRAIT, buf, sizeof(buf));
  76.             break;
  77.         default:
  78.             buf[0] = '\0';
  79.         }
  80.         SetDlgItemText(hwnd, INFO_ORIENT, buf);
  81.         switch(doc->pageorder) {
  82.         case ASCEND: 
  83.             load_string(IDS_ASCEND, buf, sizeof(buf));
  84.             break;
  85.         case DESCEND: 
  86.             load_string(IDS_DESCEND, buf, sizeof(buf));
  87.             break;
  88.         case SPECIAL:
  89.             load_string(IDS_SPECIAL, buf, sizeof(buf));
  90.             break;
  91.         default:
  92.             buf[0] = '\0';
  93.         }
  94.         SetDlgItemText(hwnd, INFO_ORDER, buf);
  95.         if (doc->default_page_media && doc->default_page_media->name) {
  96.         sprintf(buf,"%s %d %d",doc->default_page_media->name,
  97.             doc->default_page_media->width,
  98.             doc->default_page_media->height);
  99.         }
  100.         else {
  101.         buf[0] = '\0';
  102.         }
  103.         SetDlgItemText(hwnd, INFO_DEFMEDIA, buf);
  104.         sprintf(buf, "%d", doc->numpages);
  105.         SetDlgItemText(hwnd, INFO_NUMPAGES, buf);
  106.         n = map_page(psfile.pagenum - 1);
  107.         if (doc->pages)
  108.             sprintf(buf, "\"%s\"   %d", doc->pages[n].label ? doc->pages[n].label : "", psfile.pagenum);
  109.         else
  110.             buf[0] = '\0';
  111.         SetDlgItemText(hwnd, INFO_PAGE, buf);
  112.     
  113.     }
  114.     else {
  115.         if (option.ignore_dsc)
  116.             load_string(IDS_IGNOREDSC, buf, sizeof(buf));
  117.         else
  118.             load_string(IDS_NOTDSC, buf, sizeof(buf));
  119.         SetDlgItemText(hwnd, INFO_TYPE, buf);
  120.     }
  121.     sprintf(buf, "%d x %d", display.width, display.height);
  122.     SetDlgItemText(hwnd, INFO_BITMAP, buf);
  123.     }
  124.     else {
  125.     load_string(IDS_NOFILE, buf, sizeof(buf));
  126.     SetDlgItemText(hwnd, INFO_FILE, buf);
  127.     }
  128. }
  129.  
  130. /* read settings fron INI file */
  131. void
  132. read_profile()
  133. {
  134. int i;
  135. char profile[128];
  136. char *section = INISECTION;
  137. char *device_ptr;
  138. PROFILE *prf;
  139.     prf = profile_open(szIniFile);
  140.     profile_read_string(prf, section, "Version", "", profile, sizeof(profile));
  141.     if (strcmp(profile, GSVIEW_VERSION)!=0)
  142.         changed_version = TRUE;
  143.     profile_read_string(prf, section, "Origin", "", profile, sizeof(profile));
  144.     if (sscanf(profile,"%d %d", &option.img_origin.x, &option.img_origin.y) != 2) {
  145.         option.img_origin.x = option.img_origin.y = CW_USEDEFAULT;
  146.     }
  147.     profile_read_string(prf, section, "Size", "", profile, sizeof(profile));
  148.     if (sscanf(profile,"%d %d", &option.img_size.x, &option.img_size.y) != 2) {
  149.         option.img_size.x = option.img_size.y = CW_USEDEFAULT;
  150.     }
  151.     if ((option.img_size.x<32) || (option.img_size.y<32))
  152.         option.img_size.x = option.img_size.y = CW_USEDEFAULT;
  153.     profile_read_string(prf, section, "Maximized", "", profile, sizeof(profile));
  154.     if (sscanf(profile,"%d", &option.img_max) != 1)
  155.         option.img_max = 0;
  156.     profile_read_string(prf, section, "SaveSettings", "", profile, sizeof(profile));
  157.     if (sscanf(profile,"%d", &i) == 1)
  158.         option.settings = i;
  159.     profile_read_string(prf, section, "ButtonBar", "", profile, sizeof(profile));
  160.     if (sscanf(profile,"%d", &i) == 1)
  161.         option.button_show = i;
  162.     profile_read_string(prf, section, "FitWindowToPage", "", profile, sizeof(profile));
  163.     if (sscanf(profile,"%d", &i) == 1)
  164.         option.fit_page = i;
  165.     profile_read_string(prf, section, "Resolution", "", profile, sizeof(profile));
  166.     if (sscanf(profile,"%f %f", &option.xdpi, &option.ydpi) != 2) {
  167.         option.xdpi = option.ydpi = DEFAULT_RESOLUTION;
  168.     }
  169.     profile_read_string(prf, section, "ZoomResolution", "", profile, sizeof(profile));
  170.     if (sscanf(profile,"%f %f", &option.zoom_xdpi, &option.zoom_ydpi) != 2) {
  171.         option.zoom_xdpi = option.zoom_ydpi = DEFAULT_ZOOMRES;
  172.     }
  173.     profile_read_string(prf, section, "Depth", "", profile, sizeof(profile));
  174.     if (sscanf(profile,"%d", &i) == 1)
  175.         option.depth = i;
  176.     profile_read_string(prf, section, "Media", "", profile, sizeof(profile));
  177.     if (strlen(profile)!=0) {
  178.         char thismedia[20];
  179.         for (i=IDM_LETTER; i<IDM_USERSIZE; i++) {
  180.             if (!get_menu_string(IDM_MEDIAMENU, i, thismedia, sizeof(thismedia))) {
  181.             /* couldn't get menu string so flag as unknown */
  182.             option.media = IDM_USERSIZE+1;
  183.                 strncpy(option.medianame,profile,sizeof(option.medianame));
  184.             break;
  185.             }
  186.             if (!stricmp(thismedia, profile)) {
  187.                 break;
  188.             }
  189.         }
  190.         if (option.media <= IDM_USERSIZE) {
  191.             option.media = i;
  192.             strncpy(option.medianame,thismedia,sizeof(option.medianame));
  193.         }
  194.         }
  195.     profile_read_string(prf, section, "UserSize", "", profile, sizeof(profile));
  196.     if (sscanf(profile,"%d %d", &option.user_width, &option.user_height) != 2) {
  197.         /* this gives 640x480 pixels at 96dpi */
  198.         option.user_width = 480;
  199.         option.user_height = 360;
  200.     }
  201.     profile_read_string(prf, section, "EpsfClip", "", profile, sizeof(profile));
  202.     if (sscanf(profile,"%d", &i) == 1)
  203.         option.epsf_clip = i;
  204.     profile_read_string(prf, section, "EpsfWarn", "", profile, sizeof(profile));
  205.     if (sscanf(profile,"%d", &i) == 1)
  206.         option.epsf_warn = i;
  207.     profile_read_string(prf, section, "IgnoreDSC", "", profile, sizeof(profile));
  208.     if (sscanf(profile,"%d", &i) == 1)
  209.         option.ignore_dsc = i;
  210.     profile_read_string(prf, section, "Orientation", "", profile, sizeof(profile));
  211.     if (sscanf(profile,"%d", &i) == 1)
  212.         option.orientation = i+IDM_PORTRAIT;
  213.     profile_read_string(prf, section, "SwapLandscape", "", profile, sizeof(profile));
  214.     if (sscanf(profile,"%d", &i) == 1)
  215.         option.swap_landscape = i;
  216.     profile_read_string(prf, section, "Unit", "", profile, sizeof(profile));
  217.     if (sscanf(profile,"%d", &i) == 1)
  218.         option.unit = i+IDM_UNITPT;
  219.     profile_read_string(prf, section, "QuickOpen", "", profile, sizeof(profile));
  220.     if (sscanf(profile,"%d", &i) == 1)
  221.         option.quick = i;
  222.     profile_read_string(prf, section, "Safer", "", profile, sizeof(profile));
  223.     if (sscanf(profile,"%d", &i) == 1)
  224.         option.safer = i;
  225.     profile_read_string(prf, section, "AutoRedisplay", "", profile, sizeof(profile));
  226.     if (sscanf(profile,"%d", &i) == 1)
  227.         option.redisplay = i;
  228.     profile_read_string(prf, section, "SaveLastDir", "", profile, sizeof(profile));
  229.     if (sscanf(profile,"%d", &i) == 1)
  230.         option.save_dir = i;
  231.     if (option.save_dir) {
  232.         profile_read_string(prf, section, "LastDir", "", profile, sizeof(profile));
  233.         _chdir(profile);
  234.     }
  235.     profile_read_string(prf, section, "Ghostscript", "", profile, sizeof(profile));
  236.     if (profile[0] != '\0')    /* don't copy a default - assume already set */
  237.         strcpy(option.gscommand, profile);
  238.     profile_read_string(prf, section, "Printer", ",", profile, sizeof(profile));
  239.     device_ptr = strtok(profile, ",");
  240.     if (device_ptr != (char *)NULL) {
  241.         strcpy(option.device_name, device_ptr);
  242.         device_ptr = strtok(NULL, ",");
  243.         if (device_ptr != (char *)NULL)
  244.             strcpy(option.device_resolution, device_ptr);
  245.     }
  246.     profile_read_string(prf, section, "PrinterPort", "", profile, sizeof(option.printer_port)-1);
  247.     if (profile[0] != '\0')
  248.         strcpy(option.printer_port, profile);
  249.     for (i=0; i<NUMSOUND; i++) {
  250.         profile_read_string(prf, section, sound[i].entry, sound[i].file, profile, sizeof(profile));
  251.         strcpy(sound[i].file, profile);
  252.     }
  253.     profile_close(prf);
  254. }
  255.  
  256. /* write settings to INI file */
  257. void
  258. write_profile()
  259. {
  260. char profile[MAXSTR];
  261. char *section = INISECTION;
  262. int i;
  263. PROFILE *prf;
  264.     prf = profile_open(szIniFile);
  265.     profile_write_string(prf, section, "Version", GSVIEW_VERSION);
  266.     sprintf(profile, "%d %d", option.img_origin.x, option.img_origin.y);
  267.     profile_write_string(prf, section, "Origin", profile);
  268.     sprintf(profile, "%d %d", option.img_size.x, option.img_size.y);
  269.     profile_write_string(prf, section, "Size", profile);
  270.     sprintf(profile, "%d", option.img_max);
  271.     profile_write_string(prf, section, "Maximized", profile);
  272.     sprintf(profile, "%d", option.settings);
  273.     profile_write_string(prf, section, "SaveSettings", profile);
  274.     sprintf(profile, "%d", option.button_show);
  275.     profile_write_string(prf, section, "ButtonBar", profile);
  276.     sprintf(profile, "%d", option.fit_page);
  277.     profile_write_string(prf, section, "FitWindowToPage", profile);
  278.     sprintf(profile, "%g %g", option.xdpi, option.ydpi);
  279.     profile_write_string(prf, section, "Resolution", profile);
  280.     sprintf(profile, "%g %g", option.zoom_xdpi, option.zoom_ydpi);
  281.     profile_write_string(prf, section, "ZoomResolution", profile);
  282.     sprintf(profile, "%d", option.depth);
  283.     profile_write_string(prf, section, "Depth", profile);
  284.     if (option.media == IDM_USERSIZE)
  285.         strcpy(profile, "User Defined");
  286.     else
  287.         strcpy(profile, option.medianame);
  288.     profile_write_string(prf, section, "Media", profile);
  289.     sprintf(profile, "%u %u", option.user_width, option.user_height);
  290.     profile_write_string(prf, section, "UserSize", profile);
  291.     sprintf(profile, "%d", option.epsf_clip);
  292.     profile_write_string(prf, section, "EpsfClip", profile);
  293.     sprintf(profile, "%d", option.epsf_warn);
  294.     profile_write_string(prf, section, "EpsfWarn", profile);
  295.     sprintf(profile, "%d", option.ignore_dsc);
  296.     profile_write_string(prf, section, "IgnoreDSC", profile);
  297.     sprintf(profile, "%d", option.orientation - IDM_PORTRAIT);
  298.     profile_write_string(prf, section, "Orientation", profile);
  299.     sprintf(profile, "%d", option.swap_landscape);
  300.     profile_write_string(prf, section, "SwapLandscape", profile);
  301.     sprintf(profile, "%d", option.unit - IDM_UNITPT);
  302.     profile_write_string(prf, section, "Unit", profile);
  303.     sprintf(profile, "%d", option.quick);
  304.     profile_write_string(prf, section, "QuickOpen", profile);
  305.     sprintf(profile, "%d", option.safer);
  306.     profile_write_string(prf, section, "Safer", profile);
  307.     sprintf(profile, "%d", option.redisplay);
  308.     profile_write_string(prf, section, "AutoRedisplay", profile);
  309.     sprintf(profile, "%d", option.save_dir);
  310.     profile_write_string(prf, section, "SaveLastDir", profile);
  311.     if (option.save_dir) {
  312.         _getcwd(profile, sizeof(profile));
  313.         profile_write_string(prf, section, "LastDir", profile);
  314.     }
  315.     profile_write_string(prf, section, "Ghostscript", option.gscommand);
  316.     if (option.device_name[0] != '\0') {
  317.         sprintf(profile,"%s,%s",option.device_name,option.device_resolution);
  318.         profile_write_string(prf, section, "Printer", profile);
  319.     }
  320.     profile_write_string(prf, section, "PrinterPort", option.printer_port);
  321.     for (i=0; i<NUMSOUND; i++)
  322.         profile_write_string(prf, section, sound[i].entry, sound[i].file);
  323.     profile_close(prf);
  324. }
  325.  
  326.